//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Research.eResearch;
using Microsoft.Research.eResearch.Common.Linq;
using System.Text;
using System.Linq;

namespace Microsoft.Research.ScientificWorkflow.TridentModelSL
{
    /// <summary>
    /// The security principal model.
    /// </summary>
    public class SecurityPrincipalModel
    {
        /// <summary>
        /// Gets or sets the display name.
        /// </summary>
        /// <value>The display name.</value>
        public string DisplayName { get; set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>The type.</value>
        public string Type { get; set; }

        /// <summary>
        /// Gets or sets the security principal.
        /// </summary>
        /// <value>The security principal.</value>
        public ISecurityPrincipal SecurityPrincipal { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="SecurityPrincipalModel"/> class.
        /// </summary>
        /// <param name="securityPrincipal">The security principal.</param>
        public SecurityPrincipalModel(ISecurityPrincipal securityPrincipal)
        {
            if (securityPrincipal != null)
            {
                this.SecurityPrincipal = securityPrincipal;

                // Build the display name
                StringBuilder dispNameBuilder = new StringBuilder();
                dispNameBuilder.Append((securityPrincipal as INamedObject).Name);
                if (securityPrincipal.Credentials.Count > 0)
                {
                    dispNameBuilder.Append(" (");
                    securityPrincipal.Credentials.ForEach(credential => dispNameBuilder.Append(credential.Credential + ", "));
                    dispNameBuilder = dispNameBuilder.Remove(dispNameBuilder.Length - 2, 2);
                    dispNameBuilder.Append(")");
                }

                this.DisplayName = dispNameBuilder.ToString();

                //// Assign the type.
                //if (securityPrincipal is User)
                //{
                //    this.Type = "User";
                //}
                //else if (securityPrincipal is Group)
                //{
                //    this.Type = "Group";
                //}
            }
        }
    }
}
